' Copyright (c) Microsoft Corporation.  All rights reserved.


Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.WindowsAPICodePack.Shell.Taskbar

Namespace TaskbarDemo
	Partial Public Class ChildDocument
		Inherits Form
		Private initializing As Boolean = False

		Public Sub New()
			initializing = True

			InitializeComponent()

			' Progress Bar
			For Each state As String In System.Enum.GetNames(GetType(TaskbarButtonProgressState))
				comboBoxProgressBarStates.Items.Add(state)
			Next state

			comboBoxProgressBarStates.SelectedItem = "Normal"

			initializing = False
		End Sub

		Private Sub comboBoxProgressBarStates_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles comboBoxProgressBarStates.SelectedIndexChanged
			UpdateProgressBar()
		End Sub

		Private Sub UpdateProgressBar()
			If initializing Then
				Return
			End If

			Taskbar.MultipleViewProgressBar.SetState(Me, CType(System.Enum.Parse(GetType(TaskbarButtonProgressState), CStr(comboBoxProgressBarStates.SelectedItem)), TaskbarButtonProgressState))

			If Taskbar.MultipleViewProgressBar.GetState(Me) <> TaskbarButtonProgressState.Indeterminate Then
				Taskbar.MultipleViewProgressBar.SetCurrentValue(Me, progressBar1.Value)
			End If
		End Sub

		Private Sub buttonProgressBarToggle_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonProgressBarToggle.Click
			If buttonProgressBarToggle.Text = "Start" Then
				' Start the progress bar timer
				timerProgressBar.Enabled = True
				buttonProgressBarToggle.Text = "Pause"

				' Reset the progress bar if necessary
				If progressBar1.Value >= progressBar1.Maximum Then
					progressBar1.Value = 0
				End If

				' resume the taskbar progressbar
				comboBoxProgressBarStates.SelectedItem = "Normal" ' this will trigger a call to UpdateProgressBar()
			Else
				' Stop the timer
				timerProgressBar.Enabled = False
				buttonProgressBarToggle.Text = "Start"

				' Pause the taskbar progressbar too
				comboBoxProgressBarStates.SelectedItem = "Paused" ' this will trigger a call to UpdateProgressBar()
			End If

			UpdateProgressBar()
		End Sub

		Private Sub timerProgressBar_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timerProgressBar.Tick
			If Taskbar.MultipleViewProgressBar.GetState(Me) = TaskbarButtonProgressState.Normal Then
				progressBar1.Style = ProgressBarStyle.Continuous

				progressBar1.PerformStep()

				' Turn off the progress bar timer if it's done
				If progressBar1.Value >= progressBar1.Maximum Then
					timerProgressBar.Enabled = False
					buttonProgressBarToggle.Text = "Start"
				End If

				UpdateProgressBar()
			Else
				' Skip increasing the value
				If Taskbar.MultipleViewProgressBar.GetState(Me) = TaskbarButtonProgressState.Indeterminate Then
					progressBar1.Style = ProgressBarStyle.Marquee
				End If
			End If
		End Sub
	End Class
End Namespace
